package com.qckj.amz.controller;

import com.qckj.amz.domain.ConfigNode;
import com.qckj.amz.service.IConfigNodeService;
import com.qckj.amz.service.IProductTempDescService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 分类节点维护Controller
 *
 * @author luchuan
 * @since 1.0 2022-08-23
 */
@RestController
@RequestMapping("/amz/configNode")
public class ConfigNodeController extends BaseController {
    @Autowired
    private IConfigNodeService configNodeService;
    @Autowired
    private IProductTempDescService productTempDescService;
    /**
     * 查询分类节点维护列表
     * 权限请勿放开，否则在产品制作获取节点时需要配置权限，不做权限控制即可
     */
    /*@PreAuthorize("@ss.hasPermi('amz:configNode:list')")*/
    @GetMapping("/list")
    public TableDataInfo list(ConfigNode configNode) {
        Page<ConfigNode> page = configNodeService.findConfigNodePage(configNode);
        return getDataTable(page);
    }

    /**
     * 导出分类节点维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configNode:export')")
    @Log(title = "分类节点维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConfigNode configNode) {
        List<ConfigNode> list = configNodeService.findConfigNodeList(configNode);
        ExcelUtil<ConfigNode> util = new ExcelUtil<>(ConfigNode.class);
        return util.exportExcel(list, "configNode");
    }

    /**
     * 获取分类节点维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:configNode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(configNodeService.findById(id));
    }

    /**
     * 新增分类节点维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configNode:add')")
    @Log(title = "分类节点维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigNode configNode) {
        AjaxResult res = configNodeService.save(configNode);
        return res;
    }

    /**
     * 修改分类节点维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configNode:edit')")
    @Log(title = "分类节点维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigNode configNode) {
        AjaxResult res = configNodeService.save(configNode);
        return res;
    }

    /**
     * 删除分类节点维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configNode:remove')")
    @Log(title = "分类节点维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        configNodeService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

}
